<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>添加楼栋信息</title>
<!-- 项目1  楼栋1  单元1  房间1 -->
<base target="_self" />

<link href="<%=path1%>/ht/Styles/css.css" rel="stylesheet" type="text/css" />
<link href="<%=path1%>/ht/Styles/ts_css.css" rel="stylesheet" type="text/css" />
<script src="<%=path1%>/ht/Scripts/My97DatePicker/WdatePicker.js"
	type="text/javascript"></script>
<script src="<%=path1%>/ht/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="<%=path1%>/ht/Scripts/IndexManager.js" type="text/javascript"></script>
<!-- <script src="Scripts/jquery.min.js" type="text/javascript" ></script>
<script src="Scripts/jquery.validate.min.js" type="text/javascript" ></script> -->
<script type="text/javascript">
	//添加楼栋信息
	function addAjax() {
		//alert("走了么");
		$.ajax({
					data : {
						build_name : $("#build_name").val(),
						floor_count : $("#floor_count").val(),
						room_count : $("#room_count").val(),
						remark : $("#remark").val(),
						project_id : $("#project_id").val()
					},
					type : "POST",
					datatype : 'json',
					url : "<%=path1%>/qt/ht/build/addBuild.do",
					error : function(data) {
						//alert(data);
						alert("出错了");
					},
					success : function(data) {
						/* 				jQuery.each(data.projectList,function(i,item){
						 alert(item.id+","+item.name);
						 }); */
						//alert("添加楼栋成功");
						window.location.href = "<%=path1%>/qt/ht/build/selectBySqls.do?page=1&rows=5";
					}
				});
	}

 	$.ajax({
				url : "<%=path1%>/qt/ht/build/selectBySqls.do?page=1&rows=5",
				datatype : 'json',
				error : function(data) {
					alert("出错了！！");
				},
				success : function(data) {
					var len = data.msg.length;
					var html = "";
					if (len > 0) {
						data.msg.forEach(function(e) {
									if (e.project_id == project_id) {
										alert(e.project_name);
										html += "<option value="+e.project_id+" selected='selected'>"
												+ e.project_name + "</option>";
									} else {
										html += "<option value="+e.project_id+">"
												+ e.project_name + "</option>";
									}
								})
						//alert(html);
						$("#project_id").append(html);
					}
				}
			}); 
</script>
  <script type="text/javascript">
  function breaks(){
	  window.location.href="<%=path1%>/qt/ht/build/selectBySqls.do?page=1&rows=5";
  }
 </script>
<script type="text/javascript">
	function build_name111() {

		var build_name = document.getElementById("build_name").value;
		if (build_name == "" || build_name == null) {
			//alert("楼栋名称不能为空");
			//build_name.focus();
			return false;
		}
		return true;
	}

	function floor_counts() {
		var floor_count = $("#floor_count").val();
		if (floor_count == "" || floor_count == null) {
			//alert("楼栋层数不能为空");
			//$("#floor_count").focus();
			return false;
		}
		return true;
	}

	function project_ids() {
		var project_id = $("#project_id").val();
		if (project_id == "" || project_id == null) {
			//alert("所属项目编号不能为空");
			//$("#project_id").focus();
			return false;
		}
		return true;
	}
</script>
<script type="text/javascript">
    function danji(){
    	if(build_name111()==true & floor_counts()==true & project_ids()==true){
    		addAjax();
    	}else{
    		alert("红色星号为必填项！");
    	}
    }
</script>
</head>
<body>

	<form id="form1" method="post" name="form1">
		<div id="divTwo">
			<table width="100%" border="0" cellpadding="3" cellspacing="3"
				class="table_list1">
				<h2 align="center">添加楼栋信息</h2>

				<tr>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 项目名称:
					</td>
					<td width="10%" class="table_list1_style2">
					 <select id="project_id"   onblur="project_ids()" style="width:140px;" > 
					    <c:forEach items="${proj}" var="a">
					     <option value="${a.project_id}">${a.project_name}</option>
					   </c:forEach> 
					</select></td>
				</tr>

				<tr>
					<td width="50%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 楼栋名称:
					</td>
					<td width="50%" class="table_list1_style2"><input type="text"
						id="build_name" onblur="build_name111()" /></td>
				</tr>
				<tr>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 楼层数：
					</td>
					<td width="10%" class="table_list1_style2"><input type="text"
						id="floor_count" onblur="floor_counts()"/></td>
				</tr>
				
				<tr>
					<td width="10%" class="table_list1_style1"><p></p> 备注:</td>
					<td width="10%" class="table_list1_style2"><input type="text"
						id="remark" name="remark" /></td>
				</tr>

				<tr>
					<td class="table_list1_style1">

						<p></p> <input type="button" id="send" value="添加" tabindex="1"
						class="button" onclick="danji()" /> &nbsp;
					</td>
					<td width="1%" class="table_list1_style2">

						<p></p> <input type="button" class="button" value="返回"
						tabindex="1" onclick="breaks()" />
					</td>
					<td class="table_list1_style1">&nbsp;</td>
				</tr>

			</table>
		</div>
	</form>
</body>
</html>